<script type="text/javascript">
	function doSearchTransWebSite(value) {
		
	}
	
	//表格查询  
	function reloadTransWebSite() {
		var params = transWebSite_list.datagrid('options').queryParams; //先取得 datagrid 的查询参数  
		printLog(params);
		transWebSite_list.datagrid('reload'); //设置好查询参数 reload 一下就可以了  
		transWebSite_list.datagrid('unselectAll');
		transWebSite_list.datagrid('uncheckAll');
	}


	function addTransWebSite() {
		createFromWindow("新增信息", "transWebSite.do?editTransWebSite", "transWebSite.do?saveTransWebSite",
				function(data) {
					reloadTransWebSite();
				});
	}
	
	function deleteTransWebSite() {
		var rows = transWebSite_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要删除吗?',function(r){
	            if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++){
	            		ids += rows[i].id+",";
	            	}
	                $.post('transWebSite.do?deleteTransWebSiteItems',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadTransWebSite();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}

	function editTransWebSite() {
		var rows = transWebSite_list.datagrid('getChecked');
		printLog(rows);
		if (rows&&rows.length>0) {
			if(rows.length>1) {
				showMsg('请选择一条操作记录.');
				return;
			}
			createFromWindow("编辑信息", "transWebSite.do?editTransWebSite&transWebSiteId=" + rows[0].id,
					"transWebSite.do?saveTransWebSite", function(data) {
						reloadTransWebSite();
					},true);
		} else {
			showMsg('请选择操作记录.');
		}

	}
	
	
	//操作按钮触发
	function operationsLookTransWebSite(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = transWebSite_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			createFromWindow("查看信息", "transWebSite.do?editTransWebSite&transWebSiteId=" + id,
					null, null,false);
		} else {
			showMsg('请选择查看记录.');
		}
	}
	
	function operationsEditTransWebSite(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = transWebSite_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			createFromWindow("编辑信息", "transWebSite.do?editTransWebSite&transWebSiteId=" + id,
					"transWebSite.do?saveTransWebSite", function(data) {
						reloadTransWebSite();
					},true);
		} else {
			showMsg('请选择编辑记录.');
		}
	}
	
	function operationsSendTransWebSite() {
		printLog('发送');
	}
	
	function operationsDeleteTransWebSite(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = new_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			$.messager.confirm('询问', '你确认要删除吗?', function(r) {
				if (r) {
					$.post('transWebSite.do?deleteTransWebSiteItems', {
						ids : id
					}, function(result) {
						if (result.success) {
							reloadTransWebSite(); 
						}
						showMsg(result.msg);
					}, 'json');
				}
			});
		} else {
			showMsg("请选择操作记录.");
		}
	}
	
	function clearTransWebSiteSearch() {
		setGridSearchParams('transWebSite_list','transWebSiteSearchForm',true,reloadTransWebSite);
	}
	
	//根据条件查询
	function transWebSiteSearch() {
		setGridSearchParams('transWebSite_list','transWebSiteSearchForm',false,reloadTransWebSite);
	}
	
	function refreshWebSite() {
		$('#tree_trans_website').tree('reload');
	}
	
	function loadWebsiteInfo(node) {
		printLog(node);
		$.post('transWebSite.do?loadTransWebSiteInfo',{id:node.id},function(result){
       	   printLog(result);
           if (result){
           	 $("#websiteForm").form('load', result);
//            	 printLog("ttttttttttttt");
//            	 $('#parentWebsiteComboTree').combotree('reload');
//            	 $('#parentWebsiteComboTree').combotree('setValue', result.parentId); 
           } else {
        	   showMsg('加载失败.');
           }
        },'json');
	}
	
	function saveOrUpdateWebsite() {
		var validate = $('#websiteForm').form("validate");
		if(validate) {
			var actionurl = $('#websiteForm').attr('action');//提交路径
			var formData = new Object();

			var fields = $('#websiteForm').serializeArray(); //自动序列化表单元素为JSON对象  

			$.each(fields, function(i, field) {
				printLog(field.name + "=" + field.value);
				formData[field.name] = field.value;
			});
			printLog(formData);
			$.ajax({
				async : false,
				cache : false,
				type : 'POST',
				url : actionurl,// 请求的action路径
				data : formData,
				error : function() {// 请求失败处理函数
					showMsg('保存失败.');
				},
				success : function(data) {
					printLog(data);
					$('#tree_trans_website').tree('reload');
					showMsg('保存成功.');
					$('#websiteForm').form('clear');
					$('#parentWebsiteComboTree').combotree('reload');
				}
			});
		}
		
	}
	
	function addWebsite() {
		$('#websiteForm').form('clear');
// 		var root = $('#tree_trans_website').tree('getRoot');  
// 		$("#tree_trans_website").tree('uncheck',root.target); 
		
	}
	
	function deleteWebsite() {
		var node = $("#tree_trans_website").tree("getSelected");
		var isLeaf = $("#tree_trans_website").tree("isLeaf",node);
		printLog();
		if (node) {
			 $.messager.confirm('询问','你确认要删除网点吗?',function(r){
	            if (r){
	            	$.post('transWebSite.do?deleteTransWebSiteItems', {
							ids : node.id
						}, function(result) {
						if (result.success) {
							$('#tree_trans_website').tree('reload');
							$('#parentWebsiteComboTree').combotree('reload');
						}
						showMsg(result.msg);
					}, 'json');
	            }
	        });
		} else {
			showMsg('请选择左侧网点.');
		}
	}
	
	
	function selectProvince(value) {
// 		$.get('/City/GetCitysByProvinceName', { provinceName: newValue }, function (data) {
//             city.combobox("clear").combobox('loadData', data);
//             district.combobox("clear")
//         }, 'json');
		$('#cityCombobox').combobox("clear").combobox('reload','city.do?loadComboBox&provinceId='+value.value);
		$('#districtCombobox').combobox("clear");
// 		$('#websiteStateProvince').val(value.name);
		setStateProvince();
	}
	function selectCity(value) {
		$('#districtCombobox').combobox("clear").combobox('reload','district.do?loadComboBox&cityId='+value.value);
// 		var provinceName = $('#provinceCombobox').combobox("getText");
// 		$('#websiteStateProvince').val(provinceName+value.name);
		setStateProvince();
	}
	
	function selectDistrict(value) {
		setStateProvince();
	}
	
	function setStateProvince() {
		var provinceName = $('#provinceCombobox').combobox("getText");
		var cityName = $('#cityCombobox').combobox("getText");
		var districtName = $('#districtCombobox').combobox("getText");
		$('#websiteStateProvince').val(provinceName+cityName+districtName);
	}
</script>

<#assign operations = "[\{shiro:'trans:transWebSite:refresh',onClick:'operationsLookTransWebSite',src:'static/jmax/images/notes/note.png',title:'查看'},
	   					\{shiro:'trans:transWebSite:edit',onClick:'operationsEditTransWebSite',src:'static/jmax/images/notes/note_edit.png',title:'编辑'},
	   					\{shiro:'trans:transWebSite:delete',onClick:'operationsDeleteTransWebSite',src:'static/jmax/images/notes/note_delete.png',title:'删除'}
	  				   ]"/>

<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'west',split:true,title:'网点',collapsible:false,border:false,tools:[
				{
					iconCls:'icon-reload',
					handler:function(){refreshWebSite()}
				}]" style="width:200px;">
			<@eu.tree id="tree_trans_website" method="get" 
			url="transWebSite.do?websiteTree" onCheck="onCheckTree(node, checked)"
			onClick="loadWebsiteInfo(node)"/>
    </div>
	<div data-options="region:'center',border:false">
				<div id="transWebsite_toolbar" style="border-bottom:1px solid #ddd;height: auto;background:#F4F4F4">
					<@eu.linkbutton showName="新增" shiro="sys:website:add" iconCls="icon-add" onclick="addWebsite()"/>
					<@eu.linkbutton showName="删除" shiro="sys:website:delete" iconCls="icon-remove" onclick="deleteWebsite()"/>
					<@eu.linkbutton showName="更新或保存" shiro="sys:website:saveOrUpdate" iconCls="icon-save" onclick="saveOrUpdateWebsite()"/>
				</div>
			    <form id="websiteForm" action="transWebSite.do?saveTransWebSite">
			    	<table cellpadding="5">
						<input name="id" type="hidden" value="${(transWebSiteItem.id)!}" />
						<tr>
							<td class="tbLabel">名称:</td>
							<td>
								<input name="name"  class="easyui-validatebox textbox" data-options="required: true" value="${(transWebSiteItem.name)!}"/>
							</td>
							<td class="tbLabel">简称:</td>
							<td>
								<input name="simpleName"  class="easyui-validatebox textbox" data-options="required: true" value="${(transWebSiteItem.simpleName)!}"/>
							</td>
							<td class="tbLabel">账户类型:</td>
							<td>
								<@eu.comboBox name="accountType" required="true" url="common.do?loadComboBox&key=ACCOUNT_TYPE&value=${(transWebSiteItem.accountType)!}"  />
<!-- 								<input name="accountType"  class="easyui-validatebox" data-options="required: true" value="${(transWebSiteItem.accountType)!}"/> -->
							</td>
						</tr>
						<tr>
							<td>网点类型:</td>
							<td>
								<@eu.comboBox name="websiteType" required="true" url="common.do?loadComboBox&key=WEBSITE_TYPE&value=${(transWebSiteItem.websiteType)!}"  />
<!-- 								<input name="websiteType"  class="easyui-validatebox" data-options="required: true" value="${(transWebSiteItem.websiteType)!}"/> -->
							</td>
							<td>网点级别:</td>
							<td>
								<@eu.comboBox name="websiteLevel" required="true" url="common.do?loadComboBox&key=WEBSITE_LEVEL&value=${(transWebSiteItem.websiteLevel)!}"  />
<!-- 								<input name="websiteLevel"  class="easyui-validatebox" data-options="required: true" value="${(transWebSiteItem.websiteLevel)!}"/> -->
							</td>
							<td>上级网点:</td>
							<td>
								<@eu.comboTree id="parentWebsiteComboTree" url="transWebSite.do?websiteTree&websiteId=${(transWebSiteItem.parentId)!}" name="parentId" multiple="false"/>
<!-- 								<input name="parentId"  class="easyui-validatebox" data-options="required: true" value="${(transWebSiteItem.parentId)!}"/> -->
							</td>
						</tr>
						<tr>
							<td colspan="6">
							 <div class="easyui-panel" data-options="border: false" title="地址和联系方式">
							 </div>
							</td>
						</tr>
						<tr>
							<td>联系人:</td>
							<td>
								<input name="contacts"  class="easyui-validatebox textbox" data-options="required: true" value="${(transWebSiteItem.contacts)!}"/>
							</td>
							<td>手机:</td>
							<td>
								<input name="mobilePhone"  class="easyui-validatebox textbox" data-options="required: true" value="${(transWebSiteItem.mobilePhone)!}"/>
							</td>
							<td>电话:</td>
							<td>
								<input name="telephone"  class="easyui-validatebox textbox" data-options="required: true" value="${(transWebSiteItem.telephone)!}"/>
							</td>
						</tr>
						
						<#assign addressHtmlId = "webAddressHtmlId">
						<#include "/base/address.html">
						<#macro callbackFun>
							$('#websiteStateProvince').val(addressText);
						</#macro>
						<tr>
							<td>所在地区:</td>
							<td colspan="7">
								<input id="websiteStateProvince" name="stateProvince" style="width: 498px;" class="easyui-validatebox textbox"  value="${(transWebSiteItem.stateProvince)!}"/>
							</td>
						</tr>
						<tr>
							<td>地址:</td>
							<td colspan="7">
								<input id="websiteAddress" style="width: 498px;" name="address"  class="easyui-validatebox textbox" data-options="prompt: '建议您如实填写详细收货地址，例如街道名称，门牌号码，楼层和房间号等信息'"  value="${(transWebSiteItem.address)!}"/>
							</td>
						</tr>
						<tr>
							<td>邮编:</td>
							<td>
								<input name="postcode"  class="easyui-validatebox textbox" value="${(transWebSiteItem.postcode)!}"/>
							</td>
							<td>邮箱:</td>
							<td>
								<input name="email"  class="easyui-validatebox textbox" value="${(transWebSiteItem.email)!}"/>
							</td>
							<td>传真:</td>
							<td>
								<input name="fax"  class="easyui-validatebox textbox"  value="${(transWebSiteItem.fax)!}"/>
							</td>
						</tr>
						<tr>
							<td>QQ:</td>
							<td>
								<input name="qq"  class="easyui-validatebox textbox"  value="${(transWebSiteItem.qq)!}"/>
							</td>
						</tr>
						<tr>
							<td colspan="6">
							 <div class="easyui-panel"  data-options="border: false" title="备注">
							 </div>
							</td>
						</tr>
						<tr>
							<td colspan="6">
								<textarea style="height: 100px;width:772px;" rows="6"  name="remark" class="easyui-validatebox textbox" >${(transWebSiteItem.remark)!}</textarea>
							</td>
						</tr>
					</table>

			    </form>
		</div>
	</div>
</div>